﻿using AMInstantMessagingServerDao;
using BaseSimpleAPI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using UDPHelper;

namespace AMInstantMessagingServer
{
    class Program
    {
        static void Main(string[] args)
        {
            UserService user_service = new UserService();

            // 向底层注入Token的相关逻辑
            NetCallContext.CheckTokenFunc = (token) =>
            {
                if (token == null)
                    return false;

                var user = user_service.GetItemById(token.Id);
                return user.OriginalToken == token.UserData;
            };

            var udp_server = new UDPServer();
            udp_server.RouteData.Formats = new List<string> { "Controller/Action" };
            udp_server.LoadAllController();
            Console.WriteLine("Server.LoadAllController()");

            IBaseServer server = udp_server;

            server.Start();

            Console.WriteLine("Server.Start()");

            while (server.IsRuning)
                Thread.Sleep(1000);

            server.Stop();
        }
    }
}
